﻿using System;

namespace Sortering
{
    partial class Array
    {
        public static void ExchangeSort(int[] array)
        {
            for (int i = 0; i < array.Length - 1; i++)
            {
                int minst = i;

                for (int j = i + 1; j < array.Length; j++)
                {
                    if (array[minst] > array[j])
                    {
                        minst = j;
                    }
                }

                if (i < minst)
                {
                    Swap(array, minst, i);
                }
            }
        }
        public static void ExchangeSort(IComparable[] array)
        {
            for (int i = 0; i < array.Length - 1; i++)
            {
                int minst = i;

                for (int j = i + 1; j < array.Length; j++)
                {
                    if (array[minst].CompareTo(array[j]) > 0)
                    {
                        minst = j;
                    }
                }

                if (i < minst)
                {
                    Swap(array, minst, i);
                }
            }
        }
    }
}
